package com.example.userservice.util;

import com.example.userservice.entity.User;
import com.example.userservice.entity.dto.UserDtoUpdate;
import com.example.userservice.entity.dto.UserDto;
import com.example.userservice.entity.dto.UserDtoRetPassword;
import com.example.userservice.entity.vo.UserVo;
import org.springframework.beans.BeanUtils;

import java.util.List;
import java.util.stream.Collectors;

public class UserConverter {
    public static List<UserVo> getUserVoListFromUserList(List<User> userList) {
        if (userList == null) return null;
        return userList.stream()
                .map(UserConverter::getUserVoFromUser)
                .collect(Collectors.toList());
    }
    public static User getUserFromUserDto(UserDto userDto) {
        if(userDto == null) return null;
        User user = new User();
        BeanUtils.copyProperties(userDto, user);
        return user;
    }
    public static User getUserFromUserDtoResetPassword(UserDtoRetPassword userDtoRetPassword) {
        if(userDtoRetPassword == null) return null;
        User user = new User();
        BeanUtils.copyProperties(userDtoRetPassword, user);
        return user;
    }
    public static User getUserFromUserDtoUpdate(UserDtoUpdate userDtoUpdate) {
        if(userDtoUpdate == null) return null;
        User user = new User();
        BeanUtils.copyProperties(userDtoUpdate, user);
        return user;
    }
    public static UserDto getUserDtoFromUser(User user) {
        if(user == null) return null;
        UserDto userDto = new UserDto();
        BeanUtils.copyProperties(user, userDto);
        return userDto;
    }
    public static User getUserFromUserVo(UserVo userVo) {
        if(userVo == null) return null;
        User user = new User();
        BeanUtils.copyProperties(userVo, user);
        return user;
    }
    public static UserVo getUserVoFromUser(User user) {
        if(user == null) return null;
        UserVo userVo = new UserVo();
        BeanUtils.copyProperties(user, userVo);
        return userVo;
    }
}
